class Solution {
    public int rob(int[] nums) {
        if(nums.length == 1){
            return nums[0];
        }
        int preMax1 = 0,currMax1 = 0;
        int preMax2 = 0,currMax2 = 0;
        for(int i = 0;i<nums.length-1;i++){
            int temp = currMax1;
            currMax1 = Math.max(currMax1,preMax1+nums[i]);
            preMax1 = temp;

            int temp2 = currMax2;
            currMax2 = Math.max(currMax2,preMax2+nums[i+1]);
            preMax2 = temp2;
        }
        return Math.max(currMax1,currMax2);
    }
}